<%-- 
    Document   : FormPesanBarang
    Created on : Nov 20, 2013, 8:50:23 AM
    Author     : agung
--%>

<%@page import="Model.Pemesanan"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="Model.Barang"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Form Pesan Barang</title>
        <link href="css/screen.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
          <div id="container"><center> <img src="gambar/handshaking.jpg" width="1350" height="300"></center>
            
                <% session = request.getSession(false);
                    String n = (String) session.getAttribute("uname");
                    if (n != null) {
                        out.print("Anda login sebagai " + n);
                    } else {
                        out.print("Session belum ada");
                    }
                %> 
            <div id="navigation">
                <ul>
                    <li><a href="HomePelanggan.jsp">Home</a></li>
                    <li><a href="FormPesanBarang.jsp">Pesan Barang</a></li>
                    <li><a href="Logout.jsp">Logout</a></li>
                </ul>
            </div>

            <% Pemesanan barang = new Pemesanan();
                    String kode = barang.KodePemesanan();%>


            <div id="content">

                 <%
                try {
                    Connection con = KoneksiDB.Koneksi.open();
                    Statement stat = con.createStatement();
                    String cek = "select nama_barang, harga from barang";
                    ResultSet res = stat.executeQuery(cek);
            %>
            <table border="1">
                <tr  width="10" bgcolor="#94A985">
                    <td>Nama Barang</td>
                    <td>Harga</td>
                </tr>
                <%
                    while (res.next()) {
                %>
                <tr>
                    <td><%=res.getString("nama_barang")%></td>
                    <td><%=res.getString("harga")%></td>
                </tr>
                <%   }%>
            </table>
            <%
                    res.close();
                    stat.close();
                    con.close();
                } catch (Exception ex) {
                    out.println("Can't connect to database.");
                }%>
                
                <form id="FPesanBarang" name="FPesanBarang" action="PesanBarangController" onsubmit="return validateForm();"> 
                    <h1>Pesan Barang</h1>   
                    <label>Kode Pemesanan </label> : <input name="kodePemesanan" type="text" id="kodePemesanan" value="<%=kode%>" disabled=""  size="20" maxlength="20" class="txt" /><br/><br/>
                    <label>Cabang Indomaret </label> : <input name="cabang" type="text" id="cabang" size="20" maxlength="20" class="txt" /><br/><br/>
                    <label>Nama Barang </label> : <input name="namaBarang" type="text" id="namaBarang" size="20" maxlength="20" class="txt" /><br/><br/>   
                    <label>Jumlah </label> : <input name="jumlahBarang" type="text" id="jumlahBarang" size="5" maxlength="20" class="txt" /><br/><br/>   
                    <div id="tombol">
                        <input name="btnSimpan" type="submit" value="Simpan" class="button" />
                        <input name="btnReset" type="reset" value="Reset" class="button" />
                    </div> 
                </form> 

                <script>
                    function validateForm()
                    {
                        var b = document.forms["FPesanBarang"]["namaBarang"].value;
                        if (b === null || b === "")
                        {
                            alert("Nama barang masih kosong");
                            return false;
                        }
                        var c = document.forms["FPesanBarang"]["jumlahBarang"].value;
                        if (c === null || c === "")
                        {
                            alert("Jumlah barang masih kosong");
                            return false;
                        }

                    }
                </script>


            </div>
            <div id="footer">
                Copyright © Sistem Informasi Distributor Indomaret, 2013
            </div>
        </div>
    </body>
</html>
